from pyecharts.charts import Bar
from pyecharts import options as opts
 
# 创建柱状图对象
bar = Bar()
 
# 添加 X 轴和 Y 轴数据
bar.add_xaxis(["苹果", "香蕉", "橙子", "葡萄", "菠萝"])
bar.add_yaxis("销量", [120, 200, 150, 80, 70])
 
# 设置全局配置
bar.set_global_opts(title_opts=opts.TitleOpts(title="水果销量"))
 
# 渲染为 HTML 文件
bar.render("bar_chart.html")


from pyecharts.charts import Line
from pyecharts import options as opts
 
# 创建折线图对象
line = Line()
 
# 添加 X 轴和 Y 轴数据
line.add_xaxis(["1月", "2月", "3月", "4月", "5月", "6月"])
line.add_yaxis("温度", [5, 8, 15, 20, 25, 30])
 
# 设置全局配置
line.set_global_opts(title_opts=opts.TitleOpts(title="月平均温度变化"))
 
# 渲染为 HTML 文件
line.render("line_chart.html")


from pyecharts.charts import Pie
from pyecharts import options as opts
 
# 创建饼图对象
pie = Pie()
 
# 添加数据
pie.add("", [("苹果", 40), ("香蕉", 30), ("橙子", 20), ("葡萄", 10)])
 
# 设置全局配置
pie.set_global_opts(title_opts=opts.TitleOpts(title="水果比例"))
pie.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c} ({d}%)"))
 
# 渲染为 HTML 文件
pie.render("pie_chart.html")